#  增 删 改 查
#  哪些属性
class StudentManagment:

    def __init__(self,students=[]):
        self.students = students

    def addstudent(self,name,sid,age,gender):
        student = {'name': name , 'sid': sid,'age': age,'gender':gender }
        self.students.append(student)

    def del_student(self,sid):
        # 遍历students,查找sid
        res = self.find_students(sid)
        if res:
            # 删除
            self.students.remove(res)
        else:
            print('没有这个学生,无法删除')

    def change_student(self,sid):
        # 遍历students,查找sid
        res = self.find_student(sid)
        if res:
            print(res)
            # 更改
            name = input('请输入修改后的学生姓名:')
            age = input('请输入修改后的年龄:')
            gender = input('请输入修改后的学生性别:')
            res['name'] = name
            res['age'] = age
            res['gender'] = gender
        else:
            print('没有这个学生,无法更改')

    def find_student(self,sid):
        for self.student in self.students:
            if self.student.get('sid') == sid:
                return self.student
        return None

    def show_rules(self):
        print('=' * 50)
        print()
        print('1.查询学生'.center(50))
        print('2.添加学生'.center(50))
        print('3.修改学生'.center(50))
        print('4.删除学生'.center(50))
        print('5.退出系统'.center(50))
        print('6.查询所有信息'.center(50))
        print('=' * 50)

    def main(self):
        print('欢迎来到学生管理系统-函数版')
        self.show_rules()
        while 1:
            code = input('请输入操作指令:')
            if code == '1':
                print('你正在使用查询功能:')
                sid = input('请输入查询学生id')
                sid = int(sid)
                print(self.find_student(sid))
            elif code == '2':
                name = input('请输入要添加的学生姓名:')
                sid = input('请输入要添加的学生sid:')
                sid = int(sid)
                age = input('请输入要添加的学生年龄:')
                gender = input('请要添加的学生性别:')
                self.addstudent(name = name,sid = sid,age = age,gender = gender)
            elif code == '3':
                sid = input('请输入修改的学生sid:')
                sid = int(sid)
                self.change_student(sid)
            elif code == '4':
                sid = input('请输入删除学生sid:')
                sid = int(sid)
                self.del_student(sid)
            elif code == '5':
                break
            elif code == '6':
                print(self.students)
            else:
                print('指令有误!')

s = StudentManagment()
s.main()



